#include "FoodWeb.h"
#include "Consumer.h"
#include "Producer.h"
#include <algorithm>
#include <fstream>
#include <cstring>
using namespace std;

FoodWeb::FoodWeb(EcoSystem *eco_system) : 
EcoSystemObject(eco_system)
{
    memset(prey_predator_web, 0, sizeof(prey_predator_web));
    memset(predator_prey_web, 0, sizeof(predator_prey_web));
}
bool FoodWeb::is_competitive(Entity *a, Entity *b)
{
    for (int i = 0; i < FOODWEB_ARRAY_SIZE; i++)
        if (predator_prey_web[a->get_species_id()][i] && predator_prey_web[b->get_species_id()][i])
            return true;
    return false;
}

bool FoodWeb::is_prey(Entity *a, Entity *b)
{
    return predator_prey_web[b->get_species_id()][a->get_species_id()];
}

void FoodWeb::add(const unsigned int &predator,const unsigned int &prey)
{
    predator_prey_web[predator][prey] = true;
    prey_predator_web[prey][predator] = true;
}

const bool *FoodWeb::get_prey_set(Entity *source) const
{
    return predator_prey_web[source->get_species_id()];
}

const bool *FoodWeb::get_predator_set(Entity *source) const
{
    return prey_predator_web[source->get_species_id()];
}

void FoodWeb::print()
{
    for (int i = 0; i < MAX_SPECIES_COUNT; i++)
    {
        for (int j = 0; j < MAX_SPECIES_COUNT; j++)
            std::cout << predator_prey_web[i][j] << ' ';
        cout << endl;
    }

    for (int i = 0; i < MAX_SPECIES_COUNT; i++)
    {
        for (int j = 0; j < MAX_SPECIES_COUNT; j++)
            std::cout << prey_predator_web[i][j] << ' ';
        cout << endl;
    }
}
